from pages.trade_page import TradePage
from tools.driver import open_dingstock
from unittest import TestCase
from pages.recommend_page import RecommendPage
from pages.mine_page import MinePage
import unittest
from time import sleep


class TestComment(TestCase):
    def setUp(self) -> None:
        self.driver = open_dingstock()
        self.recommendpage = RecommendPage(self.driver)
        self.minepage = MinePage(self.driver)
        self.tradepage = TradePage(self.driver)
    
    def tearDown(self) -> None:
        sleep(1)

    def test_a_comment(self):
        """测试动态二级评论"""
        comment_content = "测试一下交易动态的二级评论"
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        origin = self.tradepage.get_first_trade_comment_num()
        self.tradepage.trade_comment_level2(comment_content)
        new = self.tradepage.get_first_trade_comment_num()
        assert int(origin) == int(new) - 1
        
    def test_b_comment_look_image(self):
        """测试动态二级评论查看图片"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.look_comment_image()
        assert self.tradepage.is_download_image_exist()
        
    def test_c_comment_like(self):
        """测试交易二级评论👍及取消👍"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.into_first_comment_detail()
        self.tradepage.like_level2_comment()
        sleep(1)
        origin = self.tradepage.is_level2_like_num_exist()
        self.tradepage.like_level2_comment()
        sleep(1)
        new = self.tradepage.is_level2_like_num_exist()
        assert origin == True and new == False
        
    def test_d_comment_like(self):
        """测试删除交易二级评论"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        origin = self.tradepage.get_first_trade_comment_num()
        self.tradepage.into_first_comment_detail()
        self.tradepage.delete_level2_comment()
        self.tradepage.back_trade_detail()
        new = self.tradepage.get_first_trade_comment_num()
        assert origin != new
        
    def test_e_comment_copy(self):
        """测试复制交易二级评论"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.into_second_comment_detail()
        self.tradepage.copy_level2_comment()
        assert self.tradepage.is_text_toast_exist('已复制')
        
    def test_f_comment_report(self):
        """测试举报交易二级评论"""
        self.recommendpage.switch_trade()
        self.tradepage.into_first_trade()
        self.tradepage.into_second_comment_detail()
        self.tradepage.report_level2_comment()
        assert self.tradepage.is_text_toast_exist('举报成功')
        

if __name__ == '__main__':
    unittest.main()
